<template>
	<section>
		<!--列表-->
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item class="set_width">
					<el-input v-model="filters.name" placeholder="姓名"></el-input>
				</el-form-item>
				<el-form-item class="set_width">
					<el-select placeholder="性别" value="性别" v-model="filters.gender">
						<el-option label="男" value="0"></el-option>
						<el-option label="女" value="1"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item class="set_width">
					<el-select placeholder="级别" value="请选择" v-model="filters.level">
						<el-option v-for="level in relevel"
							:key="level.id"
							:label="level.dictName"
							:value="level.id">
						</el-option>
					</el-select>
					
				</el-form-item>
				<el-form-item class="set_width">
					<el-input v-model="filters.homeAddress" placeholder="居住地"></el-input>
				</el-form-item>
				<el-form-item class="set_width">
					<el-input v-model="filters.idNum" placeholder="身份证号"></el-input>
				</el-form-item>
				<el-form-item class="set_width">
					<el-input v-model="filters.certificateNum" placeholder="裁判证号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="queryUsers">查询</el-button>
					<el-button type="success" v-on:click="resetquery">清空</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<el-table :data="users" highlight-current-row v-loading="listLoading" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="name" label="姓名" width="100" sortable>
			</el-table-column>
			<el-table-column prop="gender" label="性别" width="80" :formatter="formatSex" sortable>
			</el-table-column>
			<el-table-column prop="birthday" label="生日" width="100" sortable>
			</el-table-column>
			<el-table-column prop="idNum" label="身份证号" width="150">
			</el-table-column>
			<el-table-column prop="level" label="级别" min-width="120" :formatter="formatReLevel" sortable>
			</el-table-column>
			<el-table-column prop="certificateNum" label="国际裁判号" min-width="120" sortable>
			</el-table-column>
			<el-table-column prop="homeAddress" label="居住地" min-width="180" sortable>
			</el-table-column>
			<el-table-column prop="mobile" label="联系电话" min-width="120" sortable>
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template slot-scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">通过</el-button>
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">拒绝</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>

		<!--通过界面-->
		<el-dialog title="审核" :visible.sync="editFormVisible" :close-on-click-modal="false">
			<span>通过该裁判员的审核</span>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">确定</el-button>
			</div>
		</el-dialog>
		<!-- 拒绝界面 -->
		<el-dialog title="审核" :visible.sync="rejuectFormVisible" :close-on-click-modal="false">
			<el-input
			type="textarea"
			:autosize="{ minRows: 2, maxRows: 4}"
			placeholder="拒绝原因"
			v-model="textarea4">
			</el-input>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="rejuectFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	// import { getUserListPage, removeUser, batchRemoveUser, editUser, addUser } from '../../api/api';
	import mycommon from  '../../common/enum'
	import { getReLeve , removeUser  } from '../../api/api';
	export default {
		data() {
			return {
				filters: {
					name: '',
					gender:'',
					level: '',
					homeAddress:'',
					idNum:'',
					certificateNum:''
				},
				relevel:[], // 裁判员等级
				releveldict:{}, // 裁判员等级词典 过滤器用
				users: [],
				total: 0,
				page: 1,
				listLoading: false,
				sels: [],//列表选中列
				editFormVisible: false,// 通过页面是否显示
				rejuectFormVisible: false, // 拒绝页面是否显示
				editLoading: false,
				editFormRules: {
					name: [
						{ required: true, message: '请输入姓名', trigger: 'blur' }
					]
				},
				passId: 0,
				//编辑界面数据
				editForm: {
					id: 0,
					name: '',
					sex: -1,
					age: 0,
					birth: '',
					addr: ''
				},
				textarea3: '', // 通过原因
				textarea4: '', // 拒绝原因 
				addFormVisible: false,//新增界面是否显示
				addLoading: false,
				addFormRules: {
					name: [
						{ required: true, message: '请输入姓名', trigger: 'blur' }
					]
				},
			}
		},
		methods: {
			//  裁判员级别格式化,
			formatReLevel(row) {
				return this.releveldict["lv" + row.level];

			},
			//性别显示转换
			formatSex: function (row, column) {
				return row.gender == 0 ? '男' : row.gender == 1 ? '女' : '保密';
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
			//获取用户列表
			getUsers() {
				this.listLoading = true;
				let  useroption = {
					pageNum:this.page,
					pageSize:10,
					status: -1,
					delFlag:0,
					name: this.filters.name,
					gender: this.filters.gender,
					level: this.filters.level,
					homeAddress: this.filters.homeAddress,
					idNum: this.filters.idNum,
					certificateNum:this.filters.certificateNum

				};
				//NProgress.start();
				this.axios.get('/referee/manage/re/page', {params: useroption}).then( response => {
					
					this.listLoading = false;
					this.total = response.data.data.total;
					this.users = response.data.data.list;

				}).catch( error => {
					this.listLoading = false;
					console.log(error)
				})



				//NProgress.start();
				// getUserListPage(para).then((res) => {
				// 	this.total = res.data.total;
				// 	this.users = res.data.users;
				// 	this.listLoading = false;
				// 	//NProgress.done();
				// });
			},
						// 查询裁判员
			queryUsers(){
				this.page = 0;
				this.getUsers();
			},
			// 清空查询条件
			resetquery(){
				// 清空搜索条件，重新查询所有裁判员
				this.filters = {
					name: '',
					gender:'',
					level: '',
					homeAddress:'',
					idNum:'',
					certificateNum:''
				};
				this.page = 0;
				this.getUsers();
			},
			//拒绝
			handleDel: function (index, row) {
				this.rejuectFormVisible = true;
			},
			//显示编辑界面
			handleEdit: function (index, row) {
				this.passId = row.id;
				this.editFormVisible = true;
				// this.editForm = Object.assign({}, row);
			},
			//编辑
			editSubmit: function () {
				this.listLoading = true;
				this.editFormVisible = false;
				let para ={
					status: 0
				}

				this.axios.put('/referee/manage/re/check/'+this.passId + '?status=0',).then( response => {
					this.listLoading = false;
					console.log(response);
					if(response.data.code === '0000'){
						this.$message({message:'审核成功', type: 'success'});
						this.getUsers();
					}else{
						this.$message({message:'操作失败请稍厚再试',type:'error'});
					}
				}).catch( error => {
					this.listLoading = false;
					console.log(error)
				})
				// this.$refs.editForm.validate((valid) => {
				// 	if (valid) {
				// 		this.$confirm('确认提交吗？', '提示', {}).then(() => {
				// 			this.editLoading = true;
				// 			//NProgress.start();
				// 			let para = Object.assign({}, this.editForm);
				// 			para.birth = (!para.birth || para.birth == '') ? '' : util.formatDate.format(new Date(para.birth), 'yyyy-MM-dd');
				// 			editUser(para).then((res) => {
				// 				this.editLoading = false;
				// 				//NProgress.done();
				// 				this.$message({
				// 					message: '提交成功',
				// 					type: 'success'
				// 				});
				// 				this.$refs['editForm'].resetFields();
				// 				this.editFormVisible = false;
				// 				this.getUsers();
				// 			});
				// 		});
				// 	}
				// });
			},
		},
		mounted() {
			//初始化等级列表
			getReLeve()
			.then((res) => {
				if(res.data.code==='0000'){
					this.relevel = res.data.data.list.filter(level=>{
						return level.isDel === 0;
					});
					this.relevel.forEach(level => {
						if(level.isDel === 0){
							this.releveldict['lv'+ level.id] = level.dictName;
						}
					});
					this.getUsers();
				}
			}).catch((err) => {
				
			});
		}
	}

</script>